//
//  InUseDictController.m
//  Words2
//
//  Created by Mathieu Tozer on 13/09/06.
//  Copyright 2006 __MyCompanyName__. All rights reserved.
//

#import "InUseDictController.h"
#import "WordsAppDelegate.h"

@implementation InUseDictController

- (void)awakeFromNib {
	[self registerAsObserver];
	[super awakeFromNib];
}

- (void)registerAsObserver
{
    [self addObserver:self
		   forKeyPath:@"arrangedObjects"
			  options:(NSKeyValueObservingOptionNew |
					   NSKeyValueObservingOptionOld)
			  context:NULL];
}


- (void)observeValueForKeyPath:(NSString *)keyPath
					  ofObject:(id)object 
                        change:(NSDictionary *)change
                       context:(void *)context
{
    if (object == self && [keyPath isEqual:@"arrangedObjects"]) {
		
		/*
		 If there are no dictionaries in use by the selected language, then set the user interface appropriately 
		*/
		if([[self arrangedObjects] count] == 0){
			NSString *languageName = [[[NSApp delegate] currentlySelectedLanguage] valueForKey:@"name"];
			[noDictionariesInUseWarning setStringValue:[NSString stringWithFormat:@"There aren't any dictionaries set to look up words in %@.", languageName]];

//			[definitionsTabView selectTabViewItemWithIdentifier:@"NoDictsNotice"];

			
		}else{
			[noDictionariesInUseWarning setStringValue:@""];
		//	[definitionsTabView selectTabViewItemWithIdentifier:@"Definitions"];
			//ask the lookerupperer to connect to the dictionaries
			NSArray *dicts = [self arrangedObjects];
			[[[NSApp delegate] lookerupperer] connectToDictionaries:dicts];


		}
		
		// the same change
		[super observeValueForKeyPath:keyPath
							 ofObject:object 
							   change:change 
							  context:context];
	}
}

@end
